package cn.clq.system.service.impl;

import cn.clq.system.domain.Menu;

import cn.clq.system.domain.Role;
import cn.clq.system.mapper.MenuMapper;
import cn.clq.system.mapper.RoleMapper;
import cn.clq.system.service.IRoleService;
import cn.clq.basic.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @description: 角色实现类
 * @param: null
 * @return:
 * @author clqlongbao
 * @date: 2022/6/22 16:10
 */
@Service
public class RoleServiceImpl extends BaseServiceImpl<Role> implements IRoleService {

    @Autowired
    private RoleMapper roleMapper;


    @Override
    public void save(Role role) {
        //1.保存role表数据
        roleMapper.save(role);
        //2.修改中间表数据
        initRelationTable(role);
    }
    /**
     * @description: 修改中间表数据
     * @param: role
     * @return: void
     * @author clqlongbao
     * @date: 2022/6/22 16:49
     */
    private void initRelationTable(Role role) {
        //1.先清空历史数据
        roleMapper.removeRoleMenuByRoleId(role.getId());
        roleMapper.removeRolePermissionByRoleId(role.getId());
        //2.新增数据
        roleMapper.saveRoleMenu(role);
        roleMapper.saveRolePermission(role);
    }

    @Override
    public void update(Role role) {
        super.update(role);
    }

    @Override
    public void removeById(Long id) {
        super.removeById(id);
    }
}
